package com.zb.code.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.AccounLoginInfo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjCodeBatchService;
import com.zb.service.ZjCodeService;
import com.zb.utils.TokenUtil;
import com.zb.vo.CodeBatchGoodsUpdateVo;
import com.zb.vo.CodeBatchSelectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 编码批次表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-08-23
 */
@Api(tags = "编码批次类接口")
@RestController
@RequestMapping("/code/batch")
public class ZjCodeBatchController {
    @Resource
    private ZjCodeBatchService codeBatchService;
    @Resource
    private ZjCodeService codeService;

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.SELECT, remark = "编码档案-批次列表 - 获取批次编码列表")
    @ApiOperation("获取批次编码列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody CodeBatchSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取批次编码列表成功").data(codeBatchService.getList(custAccId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.SELECT, remark = "编码档案-批次列表 - 根据批次ID获取批次编码详情")
    @ApiOperation("根据批次ID获取批次编码详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "批次ID", required = true) Long id) {
        return Result.success("获取批次编码详情").data("row", codeBatchService.getDetailById(id));
    }

    @ApiOperation("根据批次ID获取编码列表")
    @PostMapping("/getCodeList/{id}")
    public Result getCodeList(@PathVariable @ApiParam(value = "批次ID", required = true) Long id, @RequestBody PageUtil pageUtil) {
        return Result.success("获取编码列表成功").data(codeService.getCodeList(id, pageUtil));
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.DELETE, remark = "编码档案-批次列表 - 根据编码批次ID批量删除")
    @ApiOperation("根据编码批次ID批量删除")
    @DeleteMapping("/")
    public Result delete(@RequestBody @ApiParam(value = "编码批次ID", required = true) List<Long> idList) {
        codeBatchService.deleteByIds(idList);
        return Result.success("删除编码批次成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.DELETE, remark = "编码档案-批次列表 - 批量更改编码商品信息")
    @ApiOperation("批量更改编码商品信息")
    @PutMapping("/updateCodeGoods")
    public Result updateCodeGoods(HttpServletRequest request, @RequestBody @Valid CodeBatchGoodsUpdateVo goodsUpdateVo) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        codeBatchService.updateCodeGoods(loginInfo, goodsUpdateVo);
        return Result.success("编码商品信息更改成功");
    }

}
